package cn.anlaser.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;

@MappedSuperclass
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false)
public class ParentEntity<Entity extends CommonEntity> extends CommonEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3248772532110805737L;
	@JSONField(serialize = false)
	@ManyToOne(cascade = CascadeType.PERSIST, optional = true)
	@JoinColumn(name = "PARENT_ID")
	private Entity parent;
	private int level;
	@Column(name = "SER_NO", columnDefinition = "int default 0", nullable = false)
	private int serNo;
	@JsonIgnore
	@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER, mappedBy = "parent")
	@OrderBy("serNo ASC")
	private List<Entity> subs;

}
